namespace FileReaderTool
{
    public partial class Form1 : Form
    {
        private string filePath1;
        private string filePath2;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    filePath1 = dialog.FileName;
                    button1.Text = Path.GetFileName(filePath1);
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    filePath2 = dialog.FileName;
                    button2.Text = Path.GetFileName(filePath2);
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(filePath1) || string.IsNullOrEmpty(filePath2))
            {
                MessageBox.Show("Please select both files first.");
                return;
            }

            string dataDir = Path.Combine(Application.StartupPath, "Data");
            Directory.CreateDirectory(dataDir);

            string newFilePath = Path.Combine(dataDir, "MergedFile.txt");

            try
            {
                string content1 = File.ReadAllText(filePath1);
                string content2 = File.ReadAllText(filePath2);

                File.WriteAllText(newFilePath, content1 + content2);

                MessageBox.Show($"文件合并成功！");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"发送了一个合并错误: {ex.Message}");
            }
        }
    }
}
